"""
Copyright (c) 2022 Guangdong University of Technology
PhotLab is licensed under [Open Source License].
You can use this software according to the terms and conditions of the [Open Source License].
You may obtain a copy of [Open Source License] at: [https://open.source.license/]

THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.

See the [Open Source License] for more details.

Author: Meng Xiang, Junjiang Xiang
Created: 2023/8/19
Supported by: National Key Research and Development Program of China
"""

import numpy as np
from scipy.signal import resample
import matplotlib.pyplot as plt


def re_sample(input, factor):
    """

    Args:
        input: 信号
        factor: 重采样因子

    Returns:

    """
    resampled_signal = resample(y, int(len(input) * factor))

    return resampled_signal


if __name__ == '__main__':
    x = np.linspace(0, 10, 600, endpoint=False)
    y = np.cos(x**2/6.0*5)+np.cos(x*6.28*5)+np.sin(x**2*6.28*5)+np.random.normal(0, 1)*2
    out = re_sample(x, 0.2)
    xnew = np.linspace(0, 10, len(out), endpoint=False)

    plt.plot(x, y, 'g.-', xnew, out, 'm.-', markersize=5)
    plt.legend(['data', 'resampled'], loc='best')
    plt.show()